<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,initial-scale=1.0,width=device-width" />
    <meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
    <title>我的发布</title>
    <link rel="stylesheet" type="text/css" href="../../../css/aui/aui.css" />
    <link rel="stylesheet" type="text/css" href="../../../css/html/order/get_work_frm.css" />
    <link rel="stylesheet" type="text/css" href="../../../css/html/my/myissue/myissue.css" />
    <style>

    </style>
</head>

<body>
    <div id="app" v-clock>
        <div class="tab_nav">
            <div class="aui-tab border_b" id="tab">
                <div class="aui-tab-item aui-active">求职</div>
                <div class="aui-tab-item">回收</div>
                <div class="aui-tab-item">二手</div>
            </div>
        </div>
        <!-- 我的发布 -->
        <div class="tab-content" style="margin-top:2.25rem;">
            <div class="list_wrap" v-for="o,i in list" @click="detail(o.work_id, o.recycle_id)">
                <div class="row-flex">
                    <div class="list_item_media" v-if="listType !== 1" style="width:3rem;height:3rem;overflow:hidden;">
                        <img :src="o.cover_imgurl" onerror='this.src="../../../image/portrait.png"'>
                    </div>
                    <div class="person_info" style="flex:1;">
                        <div style="font-size:0.8rem;">{{o.title}}</div>
                        <div v-if="listType !== 1" style="font-size:0.8rem;">{{o.contact}}</div>
                        <div style="color:#ccc;">发布时间：{{o.create_time}}</div>
                    </div>
                </div>
                <div class="btn-group">
                    <div class="btn" @click="delConfirm(o,i)">删除</div>
                </div>
            </div>
        </div>
    </div>
</body>
<script src="../../../script/api.js" charset="utf-8"></script>
<script src="../../../script/aui/aui-tab.js" charset="utf-8"></script>
<script src="../../../script/common/jquery-3.3.1.min.js" charset="utf-8"></script>
<script src="../../../script/common/common.js" charset="utf-8"></script>
<script src="../../../script/common/config.js" charset="utf-8"></script>
<script src="../../../script/common/vue.min.js" charset="utf-8"></script>
<script>
    apiready = function() {
        api.parseTapmode();
        vm.init();

    }

    var vm = new Vue({
        el: "#app",
        data: {
            userInfo: {},
            list: [],

            listType: 1, //tab类型
            listPage: 1, //页码
            listStatus: true, //列表状态
        },
        methods: {
            init() {
                this.userInfo = get_local("userInfo");
                //上拉加载 下拉刷新
                this.upDownLoad();
                // tab切换监听
                this.tabChange();
                // 请求数据列表
                this.getList();
            },
            getList() {
                var that = this;
                var urls = {
                    1: Config.api.UserFoundUserWorkShort,
                    2: Config.api.UserFoundUserHuiShou,
                    3: Config.api.UserFoundUserErShou,
                };
                var data = {
                    user_id: that.userInfo.user_id,
                    pages: that.listPage
                };
                _ajax(urls[that.listType], data, function(ret) {
                    if (ret.code === 200) {
                        if (that.listPage === 1) {
                            that.list = ret.data;
                        } else {
                            if (ret.data.length > 0) {
                                that.list = that.list.concat(ret.data);
                            } else {
                                that.listStatus = false;
                                $toast("没有啦！");
                            }
                        }
                    }
                });
            },
            delConfirm(o, i) {
                var that = this;
                api.confirm({
                    title: '删除',
                    msg: '是否删除该信息',
                    buttons: ['确定', '取消']
                }, function(ret, err) {
                    var index = ret.buttonIndex;
                    if (index === 1) {
                        that.del(o, i);
                    }
                });
            },
            del(o, index) {
                var that = this;
                var data = {
                    1: {
                        url: Config.api.UserFoundRemoveUserWorkShort,
                        data: {
                            user_id: that.userInfo.user_id,
                            work_id: o.work_id
                        }
                    },
                    2: {
                        url: Config.api.UserFoundRemoveUserHuiShou,
                        data: {
                            user_id: that.userInfo.user_id,
                            recycle_id: o.recycle_id
                        }
                    },
                    3: {
                        url: Config.api.UserFoundRemoveUserErShou,
                        data: {
                            user_id: that.userInfo.user_id,
                            recycle_id: o.recycle_id
                        }
                    }
                };
                _ajax(data[that.listType].url, data[that.listType].data, function(ret) {
                    if (ret.code === 200) {
                        that.list.splice(index, 1);
                        $toast("删除成功");
                    }
                });
            },
            tabChange() {
                var that = this;
                var tab = new auiTab({
                    element: document.getElementById("tab"),
                    index: 1,
                    repeatClick: false
                }, function(ret) {
                    that.list = [];
                    that.listType = ret.index;
                    that.listPage = 1;
                    that.listStatus = true;
                    that.getList();
                });
            },
            openWin(name) {
                var winInfo = {
                    // 专业用工详情
                    specialty_particulars: {
                        name: 'particulars_win',
                        url: '../../home/bus_res/specialty/particulars_win.html'
                    },
                    // 零工详情
                    odd_job_particulars: {
                        name: 'particulars_win',
                        url: '../../home/bus_res/odd_job/particulars_win.html'
                    },

                };
                if (name) {
                    open_w(winInfo[name].name, winInfo[name].url);
                } else {
                    $toast("正在开发中...");
                }
            },
            upDownLoad() {
                var that = this;
                // 下拉刷新
                push_down(function() {
                    //下拉刷新恢复
                    push_down_over();

                    that.list = [];
                    that.listPage = 1;
                    that.listStatus = true;
                    that.getList();
                });

                //上拉加载
                push_up(function() {
                    if (that.listStatus) {
                        that.listPage++;
                        that.getList();
                    }
                });
            },
            detail(work_id, recycle_id) {
                switch (this.listType) {
                    case 1:
                        open_w('my_odd_job_detail_win', './my_odd_job_detail_win.html', {
                            id: work_id
                        });
                        break;
                    case 2:
                        open_w('my_recycle_detail_win', './my_recycle_detail_win.html', {
                            id: recycle_id
                        });
                        break;
                    case 3:
                        open_w('my_used_detail_win', './my_used_detail_win.html', {
                            id: recycle_id
                        });
                        break;
                    default:

                }
            }
        }
    });
</script>

</html>
